<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="backText"></block>
			<block slot="content">分红申请</block>
		</cu-custom>
		<view class="">
			
			<view class="cu-form-group">
				<view class="title">联系人id</view>
				<input placeholder="请输入联系人id" name="member_id" v-model="formData.member_id" class="text-right" disabled="true"></input>
			</view>
			
			<view class="cu-form-group">
				<view class="title">联系人</view>
				<input placeholder="请输入联系人" name="username" v-model="formData.username" class="text-right"></input>
			</view>
			
		</view>
		<view class="text-gray text-center margin-top">资料一经提交无法修改，请核对仔细后再提交！</view>
		
		<view class="text-gray text-center margin-top" v-if="config && config.member_apply && config.member_apply.reason != null && config.member_apply.reason != ''">驳回原因:{{config.member_apply.reason}}</view>
		<view v-if="status == 3 && boss_status==1">
			<view class="margin-top-xl margin-lr " v-if="!submitIng">
				<view class="cu-btn lg bg-yellow round w100" @tap="submitApply">确认提交</view>
			</view>
			<view class="margin-top-xl margin-lr " v-else>
				<view class="cu-btn lg bg-yellow round w100">
					<text class="cu-load loading"></text>
					提交中...</view>
			</view>
		</view>
		<view v-if="status == 0">
			<view class="margin-top-xl margin-lr " >
				<view class="cu-btn lg bg-yellow round w100">
					已提交待审核</view>
			</view>
		</view>
		<view v-if="status == 1">
			<view class="margin-top-xl margin-lr " >
				<view class="cu-btn lg bg-yellow round w100">
					已通过审核</view>
			</view>
		</view>
		
		<view v-if="status == 2">
			<view class="margin-top-xl margin-lr" v-if="!submitIng">
				<view class="cu-btn lg bg-yellow round w100" @tap="submitApply">已驳回，重新提交</view>
			</view>
			<view class="margin-top-xl margin-lr padding-top-xl" v-else>
				<view class="cu-btn lg bg-yellow round w100">
					<text class="cu-load loading"></text>
					提交中...</view>
			</view>
			
		</view>
		
	</view>
</template>

<script>
	export default {
		components: {
		},
		data() {
			return {
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
				config: null,
				formData: {
					member_id: 0,
					name:'分红',
					username: '',
				},
				levelIndex: 0,
				submitIng: false,
				reset:false,
				boss_status:0,
				status:3
			}
		},
		onLoad(options) {
			if (this.$common.loginAuth(true)) {
				this.$common.getMember().then((member) => {
					this.member = member
					this.formData.member_id = member.id
					this.formData.username = member.realname
					if(member.current_level>5){
						this.boss_status=1
					}
					
				})
				this.getConfig()
				// this.$nextTick((r) => {
				// 	this.$refs.cityPicker.setSelect({
				// 		provinces_id: -1,
				// 		city_id: -1,
				// 		area_id: -1,
				// 	})
				// })
			}
		},
		methods: {
			LevelPickerChange(e) {
				// console.log(e)
				this.levelIndex = e.detail.value
			},
			submitApply() {
				if(this.submitIng) return 
				if(this.member.current_level<6 ||  this.member.current_level>10){
					this.$common.showError('权限不足')
					return
				}
				let formData = this.formData
				// formData.current_level = this.config.level[this.levelIndex].level
				if (!formData.username.trim()) {
					this.$common.showError('联系人不能为空')
					return
				}
				
				this.submitIng = true
				// console.log(formData)
				this.$http
					.post('bonus_apply', formData)
					.then((response) => {
						this.submitIng = false
						this.$common.showSuccess('提交成功，请耐心等待审核',(r)=>{
							uni.navigateTo({
								url:'/pages/member/index'
							})
						})
					})
					.catch((response) => {
						this.submitIng = false
						console.log(response)
					})
			},
			getConfig() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http
					.get('bonus_apply_config')
					.then((response) => {
						this.config = response.data.data
						
						if(this.config.member_apply != ''){
							this.formData.member_id = this.config.member_apply.member_id,
							this.formData.name= this.config.member_apply.name,
							this.formData.username= this.config.member_apply.username,
							this.status = this.config.member_apply.examine_status
						}							
						uni.hideLoading()
					})
					.catch((response) => {
						uni.hideLoading()
					})
			}
		},
	}
</script>

<style>
</style>
